package com.xonro.common.histrans.sfeg.job.update;

import com.actionsoft.bpms.commons.database.RowMap;
import com.actionsoft.bpms.schedule.IJob;
import com.actionsoft.bpms.util.DBSql;
import com.actionsoft.sdk.local.SDK;
import com.xonro.common.histrans.base.consts.SfegConst;
import org.apache.commons.lang.StringUtils;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import java.util.List;

public class updateDailyBorrow implements IJob {
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        //通过oa编号修改银行账户
        String sql = "SELECT ID,OA_NO,PROJECT_NO FROM  BO_XR_EFM_BORROW_APPLY";
        List<RowMap> otherMaps = DBSql.getMaps(sql);
        for (RowMap other : otherMaps) {
            String oaNo = other.getString("OA_NO");
            String id = other.getString("ID");
            String projectNo = other.getString("PROJECT_NO");
            if (StringUtils.isBlank(oaNo)) {
                continue;
            }
         /*   RowMap accountMap = SDK.getCCAPI().getRDSAPI(SfegConst.CCID).getMap("SELECT applycircs1 FROM tb_CheckAccountReceive  WHERE teaCode = '" + oaNo + "'  ");
            String account = accountMap.getString("applycircs1");*/

            RowMap mainMap = SDK.getCCAPI().getRDSAPI(SfegConst.CCID).getMap("SELECT curState FROM tb_MoneyInOutAll  WHERE applyCode = '" + oaNo + "'  ");
            String curState = mainMap.getString("curState");
            String project_name="";
            if (StringUtils.isNotBlank(projectNo)) {
                RowMap projectMap = DBSql.getMap("SELECT PROJECT_NAME FROM BO_XR_MDM_PROJECT WHERE PROJECT_NO='" + projectNo + "' ");
                if (null != projectMap) {
                     project_name = projectMap.getString("PROJECT_NAME");
                }

            }

            String updateSql = null;
            if ("3" .equals(curState)) {
                updateSql = "UPDATE  BO_XR_EFM_BORROW_APPLY SET PROCESS_FLAG='4',PROJECT_NAME='"+project_name+"' WHERE ID='" + id + "'";
            } else {
                updateSql = "UPDATE  BO_XR_EFM_BORROW_APPLY SET PROJECT_NAME='"+project_name+"'  WHERE ID='" + id + "'";
            }
            DBSql.update(updateSql);

        }

    }
}
